package gui;

import java.awt.Color;

import javax.swing.JLabel;

public class InformationDisplay extends Thread {
	private final JLabel componentToWriteTo;
	private final String textToWrite;
	private final Color color;
	private final long timeOut;

	public InformationDisplay(JLabel componentToWriteTo, String textToWrite, Color color, long timeOut) {
		this.componentToWriteTo = componentToWriteTo;
		this.textToWrite = textToWrite;
		this.color = color;
		this.timeOut = timeOut;
	}

	@Override
	public void run() {
		synchronized (this) {
			this.componentToWriteTo.setText(this.textToWrite);
			this.componentToWriteTo.setForeground(this.color);
			try {
				this.wait(this.timeOut);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			this.clearEntry();
		}

	}

	public void clearEntry() {
		this.componentToWriteTo.setText("");
		this.componentToWriteTo.setForeground(Color.black);
	}

}
